<%--
  Created by IntelliJ IDEA.
  User: yanqin
  Date: 2017/6/4
  Time: 13:15
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Login</title>
    <%@include file="common.jsp" %>
</head>
<body>
<nav class="navbar navbar-default" role="navigation" id="topNav">
    <div class="container-fluid">
        <h1>Login dreamteam!</h1>
    </div>
</nav>
<div class="container">
    <div class="row">
        <div class="col-md-12">
            <div class="input-group">
                    <span class="input-group-addon">
					    <span class="glyphicon glyphicon-user"></span>
                    </span>
                <input id="userid" type="text" class="form-control" placeholder="Please input the userid">
            </div>
            <br/>
            <div class="input-group">
				<span class="input-group-addon">
					<span class="glyphicon glyphicon-lock"></span>
				</span>
                <input id="password" type="password" class="form-control" placeholder="Please input the password">
            </div>
            <br/>
            <button id="login" class="btn btn-primary btn-block">Login</button>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(function () {
        $("#login").click(function () {
            var userid = $("#userid").val();
            var password = $("#password").val();
            if (userid != null && userid != '' && password != null && password != '') {
                $.ajax({
                    url:"login",
                    type:"post",
                    data:"userid="+userid+"&password="+password,
                    success:function (result) {
                        result = result.trim();
                        if(result=='success'){
                            window.location.href="../user/";
                        }else if(result=='adminSuccess'){
                            window.location.href="../admin/";
                        }else{
                            alert(result);
                        }
                    },
                    error:function (result) {
                        alert("请求错误");
                    }
                });
//                var form = $("<form action='login' method='post' hidden='hidden'></form>");
//                form.append("<input name='userid' type='text' value='" + userid + "'>");
//                form.append("<input name='password' type='text' value='" + password + "'>");
//                $(document.body).append(form);
//                form.submit();
            }
        });
    });
</script>
</body>
</html>
